$(document).ready(function() {
	$('.preview_role').click(function () {
		var url = $(this).attr('href');
		$.get(url, function (res) {
			$('#TheDialog').html(res);
			$('#TheDialog').dialog('open');
		});
		return false;
    });
	
	$('.edit_admin').click(function () {
		var url = $(this).attr('href');
		$.get(url, function (res) {
			$('#TheDialog').html(res);
			$('#TheDialog').dialog('open');
		});
		return false;
    });
	
	//列表页搜索框
	if ($('form').is('#search_form')) {
		$('form#search_form .srch').click(function() {
			$(this).parents('form').submit();
		});
	}
	
	$('.admin_status').iButton({
		labelOn: "启用",
		labelOff: "禁用",
		enableDrag: false,
		change: function(obj) {
			var status = obj.attr('checked') == 'checked' ? 1 : 0;
			var admin_id = obj.attr('name').replace('admin_id_', '');
			$.post('/admin/editstatus/admin_id/' + admin_id, {'status': status}, function(ret) {
				if (ret == 'true') {
					return true;
				} else {
					return false;
				}
			});
		}
	});
});